package com.atguigu.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.entities.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
/**
 * 客户端80端口访问该controller
 * 该controller暂时使用RestTemplate 访问8001微服务端口
 */
public class ConsumerController {
//    public static final String url ="http://localhost:8001";
    private static final String url="http://CLOUD-PAYMENT-SERVICE";
    @Autowired
    RestTemplate restTemplate;
    @GetMapping(value = "/consumer/create")
    public CommonResult<Payment> create(Payment payment) {
        //restTemplate post请求处理新增 paymeny.clas是传递参数类型
        CommonResult commonResult = restTemplate.postForObject(url+"/payment/create", payment, CommonResult.class);
        return commonResult;
    }
    @GetMapping(value = "/consumer/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable(value = "id") Long id) {
        //restTemplate post请求处理新增 paymeny.clas是传递参数类型
        CommonResult commonResult = restTemplate.getForObject(url + "/payment/get/"+id, CommonResult.class, id);

        return commonResult;
    }
}
